package com.pitb.citizenreporting;

import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;

public class LocationUtil {
	public static String getLocation(String address) {
		StringBuilder stringBuilder = new StringBuilder();
		try {
			address = URLEncoder.encode(address, "utf-8");
			String url = "http://maps.google.com/maps/geo?" + "&q=" + address
					+ "&output=csv"
					+ "&key=AIzaSyD9R4ePYDkXjAqYdTLl8L2iz8zER3pGacU";
			HttpPost httppost = new HttpPost(url);
			HttpClient client = new DefaultHttpClient();
			HttpResponse response;
			stringBuilder = new StringBuilder();
			response = client.execute(httppost);
			HttpEntity entity = response.getEntity();
			InputStream stream = entity.getContent();
			int b;
			while ((b = stream.read()) != -1) {
				stringBuilder.append((char) b);
			}
		} catch (ClientProtocolException e) {
		} catch (IOException e) {
		}
		return stringBuilder.toString();
	}
}
